<template>
  <div>
    <!--    收件箱列表-->
    <div class="email-customer" v-show="isEnd">
      <div class="make make-it">
        <div class="left">
          <el-button icon="el-icon-refresh-left" @click="toGet" size="mini"
                     style=" padding: 6.2px 15px;" :loading="showLoading">{{showLoading?'收信中':'收 信'}}
          </el-button>
          <el-button size="mini" @click="translate">分 发</el-button>
          <el-select class="next-deal" v-model="targetTime" @change="toNextDeal" size="mini">
            <el-option value="" label="稍后处理" hidden></el-option>
            <el-option value="1">今天 &nbsp;&nbsp;<span>{{todayTime}}</span></el-option>
            <el-option value="2">明天 &nbsp;&nbsp;<span>08:00</span></el-option>
            <el-option value="3">后天 &nbsp;&nbsp;<span>08:00</span></el-option>
            <el-option value="4">下周{{nextWeek}} &nbsp;&nbsp;<span>08:00</span></el-option>
            <el-option value="稍后处理" class="spec" style="cursor: pointer">
              自定义时间 &nbsp;&nbsp;<i class="el-icon-arrow-right"></i>
            </el-option>
          </el-select>
          <!--修改标记为-->
          <el-select v-model="targetLabel" @change="toLabel" size="mini"
                     class="spec-select">
            <el-option value="" label="标记为" hidden></el-option>
            <el-option v-for="item,index in common.labelListTag" :key="index"
                       :label="item.label" :value="item.value">
              <b v-show="item.labelColor" class="frag-email-icon" :style="{backgroundColor: item.labelColor}"></b>
              <span
                :style="{color:parseInt(item.value)==-3?'#2a97f9':'#606266',fontSize:parseInt(item.value)==-3?'13px':'14px'}">{{item.label }}</span>
            </el-option>
          </el-select>
          <el-select v-model="targetRemove" @change="toRemove" size="mini" placeholder="移动到"
                     class="spec-select">
            <el-option value="" label="移动到" hidden></el-option>
            <el-option label="已删除" value="4"></el-option>
            <el-option label="垃圾邮件" value="5"></el-option>
            <el-option label="归档文件" value="7"></el-option>
          </el-select>
          <el-button @click="elseEmail()" size="mini" :loading="isRebound">{{isRebound?'附件生成中':'作为附件转发'}}</el-button>
          <el-button @click="delEmail()" size="mini">删 除</el-button>
        </div>
        <!-- 固定图标-->
        <div style="display: flex;align-items: center">
          <img :title="isFixed==1?'查看全部邮件':'查看固定邮件'" style="margin-right: 15px"
               :src="isFixed==1?require('../../../../public/img/icon/fixed.png'):require('../../../../public/img/icon/fixedold.png')"
               alt="" @click="lookFixed">
          <el-input placeholder="输入邮件信息搜索" v-model="searchContent" class="input-with-select" style="width: 230px"
                    size="mini" @keyup.enter.native="handleCurrent(1)">
            <el-button slot="append" icon="el-icon-search" @click="handleCurrent(1)"></el-button>
          </el-input>
        </div>
      </div>
      <!-- 列表数据展示-->
      <div class="list-table">
        <!--表头-->
        <table class="table-title">
          <tbody>
          <tr>
            <td style="padding-left: 14px;width: 14px">
              <el-checkbox v-model="checked" @change="selectAll"></el-checkbox>
            </td>
            <td style="width: 30px;text-align: center;"><span class="el-icon-message"></span></td>
            <td width="270px">发件人昵称/邮箱</td>
            <td style="max-width: 340px">邮件主题</td>
            <td width="200px">邮件标签</td>
            <td width="150px">邮件时间</td>
            <td width="100px">操作</td>
          </tr>
          </tbody>
        </table>
        <!--内容 285-101 = 184 -->
        <div class="detail" :style="{maxHeight:$height-388+'px',minHeight:total==0?'auto':'300px'}">
          <div v-for="item,i in data" :key="i">
            <h1 class="title-table" v-show="item.total>0">{{item.title}}({{item.total}})</h1>
            <table class="table-detail">
              <tbody>
              <tr v-for="itemSon,i in item.list" :key="i" :class="{'active':itemSon.readStatus==1}"
                  @mouseover="shadowFrag=''" @mouseleave="shadowFrag=''">
                <td style="padding-left: 14px;width: 14px">
                  <input type="checkbox" v-model="tEmailInfoIds" :value="itemSon.temailInfoId"></td>
                <td style="width: 30px;text-align: center">
                  <!--是否建档-->
                  <img v-if="itemSon.emailCustomerVO.type ==0" title="陌生人"
                       src="../../../../public/img/email/icon/icon-people.png" class="delivery-img"
                       alt="陌生人">
                  <img v-else-if="itemSon.emailCustomerVO.type ==4" title="公海客户"
                       src="../../../../public/img/email/icon/icon-common.png" class="delivery-img"
                       alt="公海客户">
                  <img v-else-if="itemSon.emailCustomerVO.type ==2" title="同事建档客户"
                       src="../../../../public/img/email/icon/icon-worker.png" class="delivery-img"
                       alt="同事建档客户">
                  <img v-else-if="itemSon.emailCustomerVO.type ==3" title="共享客户"
                       src="../../../../public/img/email/icon/icon-share.png" class="delivery-img"
                       alt="共享客户">
                  <img v-else title="建档客户" src="../../../../public/img/email/icon/icon-customer.png"
                       class="delivery-img" alt="建档客户">
                </td>
                <td width="270px" @click="toDetail(itemSon)" style="position: relative"
                    @mouseover.stop="shadowFrag=itemSon.temailInfoId">
                  <span class="more" style="width: 260px;padding-right:10px;" v-html="filterEmail(itemSon,0)"
                        :class="{'fontWight':itemSon.readStatus==1}"></span>
                  <!-- 显示悬浮框-->
                  <ShadowListShow v-show="shadowFrag==itemSon.temailInfoId" ref="shadowListShow"  name="emailListTab"
                                   @moveToPerson="moveToPerson"
                                  @newCustomer="newCustomer" @editHasInfo="editHasInfo" @addHasCustomer="addHasCustomer"
                                  :item="itemSon"></ShadowListShow>
                </td>
                <td :title="itemSon.emailSubject" @click="toDetail(itemSon)">
                  <span class="more" style="max-width: 308px;padding-right: 10px"
                        :class="{'fontWight':itemSon.readStatus==1}">
                    <!--0.阿里巴巴询盘-->
                    <img v-show="itemSon.alibabaInquiry"  title="阿里巴巴询盘邮件" src="../../../../public/img/email/icon/alibaba.png"
                         class="alibaba" alt="建档客户">
                    <!--1.紧急图标 -->
                     <img v-if="parseInt(itemSon.emaileDelivery)==2" title="紧急邮件"
                          src="../../../../public/img/email/icon/icon-emps.png" class="delivery-img" alt="紧急邮件">
                    <!--2.是否回复-->
                      <img v-if="parseInt(itemSon.emailReply)==1" title="已回复"
                           src="../../../../public/img/email/icon/icon-replay.png" alt="" class="delivery-img">
                    {{itemSon.emailSubject}}
                  </span>
                </td>
                <td style="width: 200px">
                  <el-tag closable
                          v-for="itemElse in itemSon.emailLabelList"
                          :key="itemElse.labelName" :color="itemElse.labelColor"
                          @close="handleClose(itemElse.temailLabelId)">
                    {{itemElse.labelName}}
                  </el-tag>
                </td>
                <td width="150px" :title="itemSon.sendTime" @click="toDetail(itemSon)">
                  <span class="time">{{itemSon.sendTime}}</span>
                </td>
                <td width="90px" class="make-td">
                  <!-- 待办邮件-->
                  <el-tooltip placement="top" v-if="itemSon.finish==1">
                    <div slot="content">待处理事件:<br/>{{itemSon.processTime}}</div>
                    <img src="../../../../public/img/email/icon/icon-dealed.png"
                         @click="toComplete(itemSon.temailInfoId)" class="delivery-img" alt="待处理事件">
                  </el-tooltip>
                  <img v-else src="../../../../public/img/email/icon/icon-deal.png"
                       @click="toTimeDeal(itemSon.temailInfoId,itemSon.processTime)"
                       title="标记为待办邮件" class="delivery-img" alt="标记为待办邮件">
                  <span>
                    <img v-if="parseInt(itemSon.fixed)==0" src="../../../../public/img/email/icon/icon-fix.png"
                         @click="fixedTop(itemSon.temailInfoId,1)"
                         title="固定邮件" class="delivery-img" alt="固定邮件">
                  <img v-else src="../../../../public/img/email/icon/icon-fixed.png"
                       @click="fixedTop(itemSon.temailInfoId,0)"
                       title="取消固定" class="delivery-img" alt="取消固定">
                  </span>
                  <img src="../../../../public/img/email/icon/icon-del.png" @click="delEmail(itemSon.temailInfoId)"
                       title="删除邮件" class="delivery-img" alt="删除邮件">
                  <!-- 附件-->
                  <img v-show="itemSon.attachmentNumber>0" src="../../../../public/img/email/icon/icon-file.png"
                       title="邮件附件" class="delivery-img" alt="邮件附件">
                </td>
              </tr>
              </tbody>
            </table>
          </div>
        </div>
      </div>
      <div class="empty" v-show="total==0">
        <img src="../../../../public/img/empty.png" alt="">
      </div>
      <el-pagination class="fixed"
                     background align="right"
                     @current-change="handleCurrent"
                     @size-change="handleSizeChange"
                     :current-page="currentPage"
                     :page-size="size"
                     layout="total, sizes, prev, pager, next, jumper"
                     :total="total">
      </el-pagination>
      <!-- 时间选择-->
      <TimeDialog ref="timeDialog" @getData="getData"></TimeDialog>
      <!-- 分发弹框-->
      <TranslateDialog ref="translateDialog" @getData="getData"></TranslateDialog>
      <!-- 新增标签-->
      <LabelDialog ref="labelDialog" @newLabel="newLabel"></LabelDialog>
      <!--  时间选择-->
      <el-dialog :visible.sync="dialogVisible" width="500px" :close-on-click-modal="false"
                 :close-on-press-escape='false'
                 title="选择稍后处理的时间">
        <el-form ref="form" label-width="100px">
          <el-form-item label="自定义时间" style="margin: 40px 0">
            <el-date-picker size="small" v-model="nextTime" align="center" value-format="yyyy-MM-dd HH:mm:ss"
                            placeholder="自定义时间" :picker-options="pickerOptions"
                            type="datetime" :clearable="false">
            </el-date-picker>
            <!-- 底部按钮-->
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer" align="right">
          <el-button @click="cancel" size="mini">取 消</el-button>
          <el-button type="primary" size="mini" @click="submitTime">确 定</el-button>
        </div>
      </el-dialog>
      <!-- 归档文件-->
      <DocDialog ref="docDialog" @dealFoldID="dealFoldID"></DocDialog>
      <!-- start新增功能-->
      <!--    新建客户-->
      <NewCustomer ref="newCustomer" @relationCustomer="getData"
                   title="新增客户"></NewCustomer>
      <!--    编辑客户-->
      <EditCompany v-show="editCom_show" @updata="getData" title="编辑客户"
                   ref="editCustomer"></EditCompany>
      <!-- 添加已有客户-->
      <DialogAddCustomer ref="dialogAddCustomer" @relationCustomer="getData"></DialogAddCustomer>
      <!--    移入私海-->
      <DialogMovePerson @relationCustomer="getData" ref="dialogMovePerson"></DialogMovePerson>
      <!-- end新增功能-->
    </div>
  </div>
</template>
<script>
    import {mapState} from 'vuex'
    import {getHour, getNextDate, getDate, getNext, getDiffList, getTimeEmailList} from "@/util/util"
    import {getRead} from "@/api/mail/write"
    import {
        delEmail,
        emptyEmail,
        removeEmail,
        labelEmail,
        delLabel,
        getEmail,
        nextEmail,
        completeEmail,
        emptyAll,
        fixTop,
        getEmailStream
    } from "@/api/mail/make"
    import {queryEmailTypeList} from "@/api/mail/customer/slider"
    import LabelDialog from "@/components/mail/dialog/LabelDialog"
    import TimeDialog from "@/components/mail/dialog/TimeDialog"
    import TranslateDialog from "@/components/mail/dialog/TranslateDialog"
    import DocDialog from "@/components/mail/dialog/DocDialog"
    import ShadowListShow from "@/components/mail/list/ShadowListShow"
    import NewCustomer from '@/components/customer/company/emailAddUser'
    import EditCompany from '@/components/customer/company'
    import DialogAddCustomer from "@/components/mail/DialogAddCustomer";
    import DialogMovePerson from "@/components/mail/DialogMovePerson";
    export default {
        name: "EmailList",
        props: ['name'],
        components: {
            LabelDialog,
            TimeDialog,
            TranslateDialog,
            DocDialog,
            ShadowListShow,
            NewCustomer,
            EditCompany,
            DialogAddCustomer,DialogMovePerson
        },
        data() {
            return {
                isFixed: 0,
                dialogVisible: false,
                theEmail: '',
                total: 0,
                currentPage: 1,
                showHeader: false,
                checked: false,
                searchContent: '',
                data: [],
                list: [],
                size: 20,
                targetLabel: '',
                targetRemove: '',
                tEmailInfoIds: [],//所选邮件列表
                dialogTime: false,
                emailList: [],
                targetTime: '',
                todayTime: '',
                nextWeek: '',
                nextTime: '',
                userId: '',
                nextEmail: '',
                pickerOptions: {
                    disabledDate: time => {
                        return time.getTime() < Date.now() - 8.64e7
                    }
                },
                listAll: [],
                archiveFolderId: '',
                //新增
                moveArchiveFolderId: '',
                emailSubject: '',
                showLoading: false,
                isRebound: false,
                isEnd: false,
                shadowFrag: '',
                editCom_show: false,
            }
        },
        computed: {
            ...mapState(['common']),
        },
        watch: {
            dialogVisible(val) {
                if (!val) {
                    this.targetTime = ''
                }
            }
        },
        created() {
            this.currentPage = this.common.emailPage;
            this.size = this.common.emailPageSize;
            this.bus.$on('refreshEmailGet', () => {
                this.getData();
            })
        },
        mounted() {
            this.theEmail = this.common.currentEmail;
            this.getData();
            this.todayTime = getHour();
            this.nextWeek = getNextDate();
            this.bus.$on('getEmail', (params) => {
                if (params) {
                    this.userId = params.userId;
                    this.nextEmail = params.email;
                    this.theEmail = params.theEmail;
                }
                this.getData();
            })
        },
        methods: {
            //新建客户 - 区分收件箱还是已发送
            newCustomer(email) {
                this.$refs.newCustomer.init(email);
            },
            //编辑客户
            editHasInfo(custid) {
                this.editCom_show = true;
                this.$refs.editCustomer.getInit(custid);
            },
            //添加已有客户
            addHasCustomer(email) {
                this.$refs.dialogAddCustomer.getGroup(email);
            },
            //移入私海
            moveToPerson(customerID){
                this.$refs.dialogMovePerson.init(customerID);
            },
            //作为附件发送
            elseEmail() {
                if (!this.getSelectList()) return;
                if (this.tEmailInfoIds.length != 1) {
                    this.$message({
                        type: "success",
                        message: '只能选择一条邮件作为附件发送'
                    });
                    return;
                }
                let title = '';
                this.listAll.map(item => {
                    if (item.temailInfoId == this.tEmailInfoIds[0]) {
                        title = item.emailSubject;
                    }
                })
                this.isRebound = true;
                getEmailStream(this.tEmailInfoIds[0]).then(res => {
                    this.isRebound = false;
                    const result = res.data.data;
                    const params = {
                        emailSubject: "Fw:" + title,
                        emailHtmlpicList: [
                            {
                                picName: result.fileName, fileSize: result.fileSize, fileGuid: result.fileUrl
                            }
                        ]
                    };
                    const ID = this.tEmailInfoIds[0] + "d";//row.id - 临时
                    if (getDiffList(ID, 'emailListTab') == -1) {
                        this.$store.commit('SET_EMAILLISTTAB', {
                            type: 1, row: {
                                id: ID,
                                title: `Fw:${result.fileName}`,
                                file: JSON.stringify(params),
                                info: '',
                                state: 2,
                                close: true
                            }
                        })
                    } else {
                        this.$store.commit('SET_EMAILLISTTAB', {type: 0, current: ID})
                    }
                }).catch(err => {
                    this.isRebound = false;
                })
            },
            lookFixed() {
                this.isFixed = this.isFixed == 1 ? 0 : 1;
                this.handleCurrent(1)
            },
            //固定
            fixedTop(temailInfoId, type) {
                fixTop(temailInfoId, type).then(res => {
                    this.dealResult(res, 1)
                })
            },
            //已读
            getRead(temailInfoId) {
                getRead({temailInfoIds: [temailInfoId]}).then(res => {
                    this.dealResult(res, 1)
                })
            },
            //设为完成
            toComplete(tEmailInfoId) {
                this.$confirm('立即将该邮件标记为已完成状态吗?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: "success"
                }).then(() => {
                    completeEmail({temailInfoIds: [tEmailInfoId]}).then(res => {
                        this.dealResult(res)
                    }).catch(err => {
                        console.log(err)
                    });
                }).catch(() => {
                });
            },
            handleChange(val) {
                this.moveArchiveFolderId = val[val.length - 1];
            },
            //清空
            emptyAll() {
                this.$confirm('清空已删除状态所有邮件?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: "success"
                }).then(() => {
                    emptyAll({userEmail: this.common.currentEmail}).then(res => {
                        this.dealResult(res)
                    })
                }).catch(() => {
                });
            },
            //分发
            translate() {
                if (!this.getSelectList()) return;
                if (this.tEmailInfoIds.length != 1) {
                    this.$message({
                        type: "success",
                        message: '只能选择一条邮件分发'
                    });
                    return;
                }
                this.$refs.translateDialog.init(this.tEmailInfoIds[0], this.name)
            },
            //收信
            toGet() {
                if (this.common.emailList.length == 0) {
                    this.$nextTick(() => {
                        this.bus.$emit('showNotBind')
                    });
                    return;
                }
                this.showLoading = true;
                getEmail(this.common.currentEmail).then(res => {
                    this.dealResult(res)
                    this.showLoading = false;
                }).catch(err => {
                    this.showLoading = false;
                });
            },
            //全选
            selectAll(val) {
                if (val) {//全选
                    this.tEmailInfoIds = [];
                    this.listAll.map(item => {
                        this.tEmailInfoIds.push(item.temailInfoId)
                    })
                } else {
                    this.tEmailInfoIds = [];
                }
            },
            handleSizeChange(val) {
                this.size = val;
                this.$store.commit('SET_EMAILPAGESIZE', this.size)
                this.handleCurrent(1)
            },
            handleCurrent(val) {
                this.checked = false;
                this.tEmailInfoIds = [];
                this.currentPage = val;
                this.$store.commit('SET_EMAILPAGE', this.currentPage)
                this.getData();
            },
            toWrite() {
                this.bus.$emit('refreshEmailChange', -1)
                this.$router.push('/mail/write/index')
            },
            //根据邮箱+类型获取对应的邮件列表数据
            getData() {
                let email;
                if (this.nextEmail) { //下属客户
                    email = this.nextEmail
                } else if (this.theEmail) {
                    email = this.theEmail
                } else {
                    email = this.common.currentEmail
                }
                let params = {
                    userId: this.userId,//下属客户查询邮件时候需要
                    labelId: this.common.labelID,
                    query: this.searchContent,
                    emailAddress: email,
                    current: this.currentPage,
                    size: this.size,
                    archiveFolderId: this.archiveFolderId,
                    fixed: this.isFixed,
                }
                if (!this.common.labelID) {
                    params = Object.assign({}, params, {boxId: 0})
                }
                queryEmailTypeList(params).then(res => {
                    this.isEnd = true;
                    this.total = res.data.total;
                    const list = res.data.records;
                    this.listAll = list;
                    this.data = getTimeEmailList(list);
                })
            },
            //去除标记 单个
            handleClose(id) {
                delLabel(id).then(res => {
                    this.dealResult(res, 1)
                }).catch(err => {
                    console.log(err)
                });
            },
            //去详情页面
            toDetail(row) {
                sessionStorage.setItem("lastpath", this.$route.fullPath)
                this.$store.commit('SET_EMAILPAGE', this.currentPage)
                this.$store.commit('SET_EMAILPAGESIZE', this.size)
                const ID = row.temailInfoId + "a";//row.id - 临时
                if (getDiffList(ID, 'emailListTab') == -1) {
                    this.$store.commit('SET_EMAILLISTTAB', {
                        type: 1, row: {
                            id: ID,
                            title: row.emailSubject,
                            state: 1,
                            close: true
                        }
                    })
                } else {
                    this.$store.commit('SET_EMAILLISTTAB', {type: 0, current: ID})
                }
            },
            //标记为 -1 已读 -2 全部已读 -3 新增标签  其他 - 标记未标签
            toLabel(val) {
                const current = parseInt(val);
                this.targetLabel = '';
                if (current != -2 && !this.getSelectList()) return;
                switch (current) {
                    case -1:
                        this.isRead(-1);
                        break;
                    case -2:
                        this.isRead({
                            boxId: 0,
                            userEmail: this.common.currentEmail,
                            tagId: this.common.labelID,
                            archiveFolderId: this.archiveFolderId
                        });
                        break;
                    case -3:
                        this.$nextTick(() => {
                            this.$refs.labelDialog.init();
                        })
                        break;
                    default:
                        labelEmail({
                            tagId: current,
                            temailInfoIds: this.tEmailInfoIds
                        }).then(res => {
                            this.dialogTime = false;
                            this.dealResult(res, 1)
                        }).catch(err => {
                            console.log(err)
                        });
                }

            },
            //移动邮件
            toRemove(val) {
                if (!this.getSelectList()) {
                    this.targetRemove = '';
                    return;
                }
                if (val == '7') { //选择归档文件夹
                    this.$refs.docDialog.init();
                    this.targetRemove = '';
                } else {
                    this.moveEmail();
                }
            },
            dealFoldID(id) {
                this.moveArchiveFolderId = id;
                this.moveEmail();
            },
            moveEmail() {
                removeEmail({
                    boxId: this.moveArchiveFolderId ? 7 : this.targetRemove,
                    temailInfoIds: this.tEmailInfoIds,
                    archiveFolderId: this.moveArchiveFolderId
                }).then(res => {
                    this.dialogTime = false;
                    this.dealResult(res)
                }).catch(err => {
                    console.log(err)
                });
            },
            //彻底删除
            emptyEmail() {
                if (!this.getSelectList()) return;
                this.$confirm('彻底删除选中的邮件，确认?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: "success"
                }).then(() => {
                    emptyEmail(this.tEmailInfoIds).then(res => {
                        this.dealResult(res)
                    }).catch(err => {
                        console.log(err)
                    });
                }).catch(() => {
                });
            },
            //标记为待办
            toTimeDeal(id, processTime) {
                this.$refs.timeDialog.init(id, processTime);
                this.dialogTime = true;
            },
            //稍后处理
            toNextDeal() {
                if (!this.getSelectList()) {
                    this.targetTime = '';
                    return;
                }
                if (this.targetTime == '稍后处理') {
                    this.dialogVisible = true;
                } else {
                    this.submitTime()
                }
            },
            submitTime() {
                const time = this.getTime();
                if (time.indexOf('NaN') != -1) {//，没找到
                    this.$message({
                        type: "success",
                        message: '请选择自定义时间'
                    });
                    return;
                }
                this.targetTime = '';
                this.nextTime = '';
                this.dialogVisible = false;
                nextEmail({
                    processTime: time,
                    temailInfoIds: this.tEmailInfoIds
                }).then(res => {
                    this.dealResult(res, 1)
                    this.bus.$emit('refreshEmailNum')
                }).catch(err => {
                    console.log(err)
                });
            },
            getTime() {
                switch (this.targetTime) {
                    case '1':
                        return getDate(0) + " " + this.todayTime + ":00";
                    case '2':
                        return getDate(1) + " 08:00:00";
                    case '3':
                        return getDate(2) + " 08:00:00";
                    case '4'://下周
                        let result;
                        if (this.nextWeek == '一') {
                            result = getNext(1)
                        } else if (this.nextWeek == '二') {
                            result = getNext(2)
                        } else if (this.nextWeek == '三') {
                            result = getNext(3)
                        }
                        return result + " 08:00:00";
                    case '稍后处理':
                        return this.nextTime;
                    default:
                        return
                }
            },
            newLabel() {
                var labelID = this.common.labelList[0].id
                labelEmail({
                    tagId: labelID,
                    temailInfoIds: this.tEmailInfoIds
                }).then(res => {
                    this.dialogTime = false;
                    this.dealResult(res, 1)
                }).catch(err => {
                    console.log(err)
                });
            },
            isRead(params) {
                let param = {
                    temailInfoIds: this.tEmailInfoIds
                }
                if (params != -1) {
                    param = Object.assign({}, param, params)
                }
                getRead(param).then(res => {
                    this.dealResult(res, 1)
                })
            },
            //删除邮件
            delEmail(id) {
                let delArr = [];
                if (id) {
                    delArr.push(id)
                } else {
                    if (!this.getSelectList()) {
                        return;
                    } else {
                        delArr = this.tEmailInfoIds
                    }
                }
                if (delArr.length == 0) {
                    this.$message({
                        type: "success",
                        message: '请先选择要操作的邮件'
                    });
                    return;
                }
                this.$confirm('是否删除选中邮件?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: "success"
                }).then(() => {
                    //获取选中的邮件列表
                    delEmail(delArr).then(res => {
                        this.dealResult(res)
                    }).catch(err => {
                        console.log(err)
                    })
                }).catch(() => {
                });
            },
            dealResult(res, index) {
                if (res.data.success) {
                    this.checked = false;
                    this.targetRemove = this.targetLabel = '';
                    this.tEmailInfoIds = [];
                    this.bus.$emit('refreshEmailNum')
                    this.$message({
                        type: "success",
                        message: res.data.msg
                    });
                    let page = index ? this.currentPage : 1;
                    this.handleCurrent(page);
                } else {
                    this.$message({
                        type: "success",
                        message: res.data.msg
                    });
                }
            },
            //获取选择的邮件
            getSelectList(param) {
                if (this.tEmailInfoIds.length === 0) {
                    this.$message({
                        type: "success",
                        message: '请先选择要操作的邮件'
                    });
                    return false
                } else {
                    return true;
                }
            },
            cancel() {
                this.dialogVisible = false;
                this.nextTime = '';
                this.targetTime = ''
            },
            filterEmail(row, state) {
                const type = row.emailCustomerVO.type;
                if (type != 0) {
                    let str = row.emailCustomerVO.contactName + " | " + row.emailCustomerVO.enterpriseName;
                    return state ? str + row.emailCustomerVO.email : str;
                }
                const name = row.senderNickName;
                const email = row.senderEmail;
                let str = '';
                if (name) {
                    if (name.indexOf("@") != -1) {
                        return name.split("@")[0] + " | " + email
                    }
                    str = name + " | " + email
                } else {
                    str = email.split("@")[0] + " | " + email
                }
                return str;
            }
        },
        beforeDestroy() {
            this.bus.$off('getEmail');
            this.bus.$off('refreshEmailGet');
        }
    }
</script>

<style scoped lang="scss">
  @import "../../../styles/email";
</style>
